package bytebuffer;

import java.util.ArrayList;
import java.util.List;

import io.Animal;
import io.AnimalHolder;
import io.ByteSerializable;

public class Encoder {

   //private ByteBuffer byteBuffer = new ByteB
   List<Object> objectList;
   
   public Encoder() {

   }
   
   public List<Object> encode(Object object) {
      objectList = new ArrayList<Object>();
      createByteArray(object);
      return objectList;
   }
   
   private Object createByteArray(Object object) {
      
      ByteSerializable serializableObject = (ByteSerializable) object;
      Object[] initParams = serializableObject.getConstructorObject();
      for (int i = 0; i < initParams.length; i++) {
         Object param = initParams[i];
         if (param.getClass().equals(int.class) || param.getClass().equals(Integer.class)) {
            //initParams[i] = 0;
            objectList.add(param);
            System.out.println(param);
         } else {
            if (param instanceof ByteSerializable) {
               createByteArray(param);
            } else {
               System.out.println("ERROR: " + param + " does not implement ByteSerializable");
            }
            
         }
      }
      return null;
   }
   
}
